package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 *
 */
@Slf4j
@RestController
@RequestMapping("/shopping")
public class CategoriesController {
    @Reference(timeout = 3000,retries = 2, check = false)
    IProductCateService iProductCateService;


    @RequestMapping("/categories")
    @Anoymous
    //实际上没有传参 直接显示的list
    public ResponseData categoriesList(HttpServletRequest request) {
       // HttpServletRequest 封装成 AllProductCateRequest
        String sort = request.getParameter("sort");
        AllProductCateRequest allProductCateRequest = new AllProductCateRequest();
        allProductCateRequest.setSort(sort);

        AllProductCateResponse response = iProductCateService.getAllProductCate(allProductCateRequest);
        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response.getProductCateDtoList());
        }
            return new ResponseUtil().setErrorMsg(response.getMsg());


//        不要求携带key
//        String userInfo = (String) request.getAttribute(TokenIntercepter.USER_INFO_KEY);
//        JSONObject object = JSON.parseObject(userInfo);
//        Long uid = Long.parseLong(object.get("uid").toString());


    }




}
